﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace RaiderManagerBackend
{
    public static class BusinessLogic
    {
        public static void Test()
        {

            Player quickhorn = new Player();
            quickhorn.Name = "Quickhorn";
            //quickhorn.OfficerGrade = "A";
            quickhorn.SavePlayer();

            quickhorn.OfficerGrade = "A";
            quickhorn.SavePlayer();

            Player picardo = new Player();

            picardo.Name = "Picardo";
            picardo.OfficerGrade = "C";
            picardo.SavePlayer();

            

            Raid raid = new Raid();
            raid.Date = DateTime.Now;
            raid.SaveRaid();

            raid.Date = raid.Date.AddDays(2);
            raid.SaveRaid();

            Encounter halfus = new Encounter(raid);
            halfus.BossName = "Halfus";
            halfus.Location = "BoT";
            halfus.SaveEncounter();

            halfus.Location = "BastionTwilight";
            halfus.SaveEncounter();

            AttendanceEntry picAttendance = new AttendanceEntry(picardo, raid);
            picAttendance.AttendanceCode = Enumerations.AttendanceCode.Participated;
            picAttendance.SignUpCode = Enumerations.SignUpCode.Available;
            picAttendance.SaveAttendanceEntry(); //automatically adds the entry to the raid and player passed in.

            Random r = new Random();

            for (int i = 0; i < 16; i++)
            {
                AttendanceEntry QuickAttendance = new AttendanceEntry(quickhorn, raid);
                QuickAttendance.AttendanceCode = (Enumerations.AttendanceCode)r.Next(0, 4);
                QuickAttendance.SignUpCode = (Enumerations.SignUpCode)r.Next(0,3);
                QuickAttendance.SaveAttendanceEntry();
            }

            PlayerPerformanceEntry picPerformance = new PlayerPerformanceEntry(raid, halfus, picardo);
            picPerformance.DPS = 12000;
            picPerformance.MedianDPSForSpecAndEncounter = 11000;
            picPerformance.SavePerformanceEntry();

            PlayerPerformanceEntry quickPerformance = new PlayerPerformanceEntry(raid, halfus, quickhorn);
            quickPerformance.DPS = 11000;
            quickPerformance.MedianDPSForSpecAndEncounter = 12000;
            quickPerformance.SavePerformanceEntry();
            quickhorn.CalculatePerformanceGrade();
            quickhorn.CalculateAttendanceGrade();
            quickhorn.CalculateOverallGrade();
            quickhorn.OfficerGrade = "A";
            quickhorn.CalculateOverallGrade();
        }

        /// <summary>
        /// Returns a letter grade based on a point grade.
        /// </summary>
        /// <param name="gradePoint"></param>
        /// <returns></returns>
        public static string GetGradeFromGradePoint(double gradePoint)
        {
            if (gradePoint < (2 / 3))
            {
                return "F";
            }
            else if (gradePoint < 1)
            {
                return "D-";
            }
            else if (gradePoint < (4 / 3))
            {
                return "D";
            }
            else if (gradePoint < (5 / 3))
            {
                return "D+";
            }
            else if (gradePoint < 2)
            {
                return "C-";
            }
            else if (gradePoint < (7 / 3))
            {
                return "C";
            }
            else if (gradePoint < (8 / 3))
            {
                return "C+";
            }
            else if (gradePoint < 3)
            {
                return "B-";
            }
            else if (gradePoint < (10 / 3))
            {
                return "B";
            }
            else if (gradePoint < (11 / 3))
            {
                return "B+";
            }
            else if (gradePoint < 12)
            {
                return "A-";
            }
            else
                return "A";
        }

    }
}
